package com.ruoyi.whole.service.impl;

import java.util.List;

import com.ruoyi.evaluate.infoprojectevaluate.domain.InfoProjectEvaluate;
import com.ruoyi.evaluate.infoprojectevaluate.vo.ProjectEvaluateDetailVo;
import com.ruoyi.evaluate.infoprojectevaluateindex.domain.InfoProjectEvaluateIndex;
import com.ruoyi.whole.domain.*;
import com.ruoyi.whole.mapper.InfoWholeIndexMapper;
import com.ruoyi.whole.mapper.InfoWholePlanMapper;
import com.ruoyi.whole.mapper.InfoWholeTargetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.whole.mapper.InfoWholeEvaluateMapper;
import com.ruoyi.whole.service.IInfoWholeEvaluateService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 部门自评Service业务层处理
 *
 * @author ruoyi
 * @date 2022-02-14
 */
@Service
public class InfoWholeEvaluateServiceImpl implements IInfoWholeEvaluateService
{
    @Autowired
    private InfoWholeEvaluateMapper infoWholeEvaluateMapper;
    @Autowired
    private InfoWholePlanMapper infoWholePlanMapper;
    @Autowired
    private InfoWholeTargetMapper infoWholeTargetMapper;
    @Autowired
    private InfoWholeIndexMapper infoWholeIndexMapper;

    /**
     * 查询部门自评
     *
     * @param id 部门自评主键
     * @return 部门自评
     */
    @Override
    public InfoWholeEvaluate selectInfoWholeEvaluateById(Long id)
    {
        return infoWholeEvaluateMapper.selectInfoWholeEvaluateById(id);
    }

    /**
     * 查询部门自评列表
     *
     * @param infoWholeEvaluate 部门自评
     * @return 部门自评
     */
    @Override
    public List<InfoWholeEvaluate> selectInfoWholeEvaluateList(InfoWholeEvaluate infoWholeEvaluate)
    {
        return infoWholeEvaluateMapper.selectInfoWholeEvaluateList(infoWholeEvaluate);
    }

    /**
     * 新增部门自评
     *
     * @param infoWholeEvaluate 部门自评
     * @return 结果
     */
    @Override
    public int insertInfoWholeEvaluate(InfoWholeEvaluate infoWholeEvaluate)
    {
        return infoWholeEvaluateMapper.insertInfoWholeEvaluate(infoWholeEvaluate);
    }

    /**
     * 修改部门自评
     *
     * @param infoWholeEvaluate 部门自评
     * @return 结果
     */
    @Override
    public int updateInfoWholeEvaluate(InfoWholeEvaluate infoWholeEvaluate)
    {
        return infoWholeEvaluateMapper.updateInfoWholeEvaluate(infoWholeEvaluate);
    }

    /**
     * 批量删除部门自评
     *
     * @param ids 需要删除的部门自评主键
     * @return 结果
     */
    @Override
    public int deleteInfoWholeEvaluateByIds(Long[] ids)
    {
        return infoWholeEvaluateMapper.deleteInfoWholeEvaluateByIds(ids);
    }

    /**
     * 删除部门自评信息
     *
     * @param id 部门自评主键
     * @return 结果
     */
    @Override
    public int deleteInfoWholeEvaluateById(Long id)
    {
        return infoWholeEvaluateMapper.deleteInfoWholeEvaluateById(id);
    }

    @Override
    public List<InfoWholeEvaluate> selectProjectEvaluateByProjectId(Long id) {
        return infoWholeEvaluateMapper.selectProjectEvaluateByProjectId(id);
    }
    //审核状态 0 待下达 1 待填报 2 待审核 3 通过 4 已退回
    @Override
    @Transactional
    public InfoWholeEvaluate editExamineEvaluate(InfoBulkAddVo infoBulkAddVo) {
        //填写实际完成值
        InfoWholeEvaluate infoWholeEvaluate=infoBulkAddVo.getInfoWholeEvaluate();
        infoWholeEvaluateMapper.updateInfoWholeEvaluate(infoWholeEvaluate);
        return infoWholeEvaluateMapper.selectInfoWholeEvaluateById(infoWholeEvaluate.getId());
    }



    @Override
    public int uploadFiles(InfoWholeEvaluate infoWholeEvaluate) {
        Long id=infoWholeEvaluate.getId();
        //读取这个文件地址
        String fileUrl = infoWholeEvaluate.getReportUrl();
        String fileName=infoWholeEvaluate.getReportName();
        InfoWholeEvaluate infoWholeEvaluate1=infoWholeEvaluateMapper.selectInfoWholeEvaluateById(id);
        infoWholeEvaluate1.setReportUrl(fileUrl);
        infoWholeEvaluate1.setReportName(fileName);
        int i=infoWholeEvaluateMapper.updateInfoWholeEvaluate(infoWholeEvaluate1);
        return i;
    }

    @Override
    public InfoBulkAddVo getBmEvaluateDetail(Long id) {
        InfoBulkAddVo infoBulkAddVo = new InfoBulkAddVo();
        InfoWholeEvaluate infoWholeEvaluate = infoWholeEvaluateMapper.selectInfoWholeEvaluateById(id);
        InfoWholeTarget infoWholeTarget = infoWholeTargetMapper.selectInfoWholeTargetById(infoWholeEvaluate.getWholeId());
        //1.查询项目信息
        List<InfoWholePlan> list = infoWholePlanMapper.selectInfoWholePlansId(infoWholeTarget.getId());
        List<InfoWholeIndex> list1 = infoWholeIndexMapper.selectInfoWholeIndicesId(infoWholeTarget.getId());
        infoBulkAddVo.setInfoWholeTarget(infoWholeTarget);
        infoBulkAddVo.setInfoWholeEvaluate(infoWholeEvaluate);
        infoBulkAddVo.setInfoWholePlans(list);
        infoBulkAddVo.setInfoWholeIndices(list1);
        return infoBulkAddVo;
    }
}
